package com.spzx.product.controller;


import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.domain.CategoryBrand;
import com.spzx.product.service.CategoryBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/categoryBrand")
@Tag(name = "商品分类品牌管理模块")
public class CategoryBrandController extends BaseController {

    @Resource
    CategoryBrandService categoryBrandService;


    @Operation(summary = "带条件分页查询分类品牌列表")
    @GetMapping("/list")
    public TableDataInfo list(CategoryBrand categoryBrand){
        return getDataTable(categoryBrandService.selectList(categoryBrand));
    }
    @Operation(summary = "查询所有分类品牌")
    @GetMapping
    public AjaxResult listAll(){
        List<CategoryBrand> list = categoryBrandService.list();
        return success(categoryBrandService.list());
    }

    @Operation(summary = "根据id查询分类品牌详情")
    @GetMapping("/{id}") //分类品牌id
    public AjaxResult getById(@PathVariable("id")Long id){

        return success(categoryBrandService.selectCategoryBrandById(id));
    }
    @Operation(summary = "新增分类品牌")
    @PostMapping
    public AjaxResult add(@RequestBody @Validated CategoryBrand categoryBrand){
            categoryBrandService.checkUniqueCategoryBrand(categoryBrand);
        return success(categoryBrandService.save(categoryBrand));
    }


    @Operation(summary = "根据id更新分类品牌")
    @PutMapping
    public AjaxResult updateById(@Validated @RequestBody CategoryBrand categoryBrand){
        categoryBrandService.checkUniqueCategoryBrand(categoryBrand);
        return success(categoryBrandService.updateById(categoryBrand));
    }

    @Operation(summary = "根据id批量删除分类品牌")
    @DeleteMapping("{ids}")
    public AjaxResult deleteByIds(@PathVariable("ids") List<Long> ids){
        return toAjax(categoryBrandService.removeBatchByIds(ids));
    }


}
